part of 'header.dart';

// class NewsDetailPraiseBtn extends StatefulWidget {
//   const NewsDetailPraiseBtn(
//       {Key? key, required this.callback, required this.isPraised})
//       : super(key: key);
//   final bool isPraised;
//   final VoidCallback callback;

//   @override
//   _NewsDetailPraiseBtnState createState() => _NewsDetailPraiseBtnState();
// }

// class _NewsDetailPraiseBtnState extends State<NewsDetailPraiseBtn>
//     with TickerProviderStateMixin {
//   bool isPraised = false;
//   late AnimationController animCtrl;
//   late Animation<double> anim;

//   @override
//   void initState() {
//     super.initState();
//     isPraised = widget.isPraised;
//     animCtrl = AnimationController(
//         duration: const Duration(milliseconds: 300), vsync: this);

//     anim = Tween(begin: 1.0, end: 2.0).animate(
//       CurvedAnimation(
//         parent: animCtrl,
//         curve: Curves.easeIn,
//       ),
//     );
//     anim.addStatusListener((status) {
//       if (status == AnimationStatus.completed) {
//         animCtrl.reverse();
//       }
//     });
//   }

//   @override
//   void dispose() {
//     animCtrl.dispose();
//     super.dispose();
//   }

//   @override
//   Widget build(BuildContext context) {
//     return InkWell(
//       onTap: () {
//         if (animCtrl.isAnimating) {
//           return;
//         }
//         anim.addListener(() {
//           setState(() {});
//         });

//         animCtrl.forward();
//         widget.callback();
//       },
//       child: Container(
//         padding: EdgeInsets.symmetric(horizontal: 15.r),
//         constraints: BoxConstraints(minWidth: 55.r, maxWidth: 200.r),
//         height: 35.r,
//         decoration: BoxDecoration(
//             border: Border.all(
//                 color: isPraised ? ColorsUtil.green : const Color(0xffdddddd),
//                 width: 0.5.r),
//             borderRadius: BorderRadius.circular(37.5.r)),
//         child: Row(
//           mainAxisAlignment: MainAxisAlignment.center,
//           mainAxisSize: MainAxisSize.min,
//           children: [
//             ScaleTransition(
//               scale: anim,
//               child: Icon(
//                 IconUtil.praise,
//                 size: 14.r,
//                 color: isPraised ? ColorsUtil.green : ColorsUtil.title,
//               ),
//             ),
//             SizedBox(
//               width: 5.r,
//             ),
//             Text(
//               '215',
//               style: pfMediumStyle(
//                   color: isPraised ? ColorsUtil.green : ColorsUtil.title,
//                   fontSize: font12),
//             )
//           ],
//         ),
//       ),
//     );
//   }
// }

class NewsDetailPraiseBtn extends StatelessWidget {
  NewsDetailPraiseBtn({
    Key? key,
    required this.callback,
    required this.isPraised,
    required this.isAnimating,
  }) : super(key: key);
  final bool isPraised;
  final bool isAnimating;
  final void Function(GlobalKey) callback;
  GlobalKey animKey = GlobalKey();
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => callback(animKey),
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 15.r),
        constraints: BoxConstraints(minWidth: 55.r, maxWidth: 200.r),
        height: 35.r,
        decoration: BoxDecoration(
            border: Border.all(
                color: isPraised ? ColorsUtil.green : const Color(0xffdddddd),
                width: 0.5.r),
            borderRadius: BorderRadius.circular(37.5.r)),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: [
            PraiseAnimateWidget(
              key: animKey,
              isAnimating: isAnimating,
              isPraised: isPraised,
            ),
            SizedBox(
              width: 5.r,
            ),
            Text(
              '215',
              style: pfMediumStyle(
                  color: isPraised ? ColorsUtil.green : ColorsUtil.title,
                  fontSize: font12),
            )
          ],
        ),
      ),
    );
  }
}

class PraiseAnimateWidget extends StatefulWidget {
  const PraiseAnimateWidget(
      {Key? key, required this.isPraised, required this.isAnimating})
      : super(key: key);
  final bool isPraised;
  final bool isAnimating;
  @override
  _PraiseAnimateWidgetState createState() => _PraiseAnimateWidgetState();
}

class _PraiseAnimateWidgetState extends State<PraiseAnimateWidget>
    with SingleTickerProviderStateMixin {
  bool isPraised = false;
  bool isAnimating = false;
  late AnimationController animCtrl;
  late Animation<double> anim;

  @override
  void initState() {
    super.initState();
    isPraised = widget.isPraised;
    isAnimating = widget.isAnimating;
    animCtrl = AnimationController(
        duration: const Duration(milliseconds: 300), vsync: this);

    anim = Tween(begin: 1.0, end: 2.0).animate(
      CurvedAnimation(
        parent: animCtrl,
        curve: Curves.easeIn,
      ),
    );
    anim.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        animCtrl.reverse();
      }
    });
    if (isAnimating) {
      animation();
    }
  }

  void animation() {
    if (animCtrl.isAnimating) {
      return;
    }
    animCtrl.forward();
  }

  @override
  void dispose() {
    animCtrl.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return ScaleTransition(
      scale: anim,
      child: Icon(
        IconUtil.praise,
        size: 14.r,
        color: isPraised ? ColorsUtil.green : ColorsUtil.title,
      ),
    );
  }
}

class NewsDetailHeaderRecommendView extends StatelessWidget {
  const NewsDetailHeaderRecommendView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: gap12, vertical: gap15),
      child: Row(
        children: [
          ClipRRect(
            child: loadImage(width: 110.r, height: 70.r),
          ),
          SizedBox(
            width: gap10,
          ),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  '退伍军人“玩转”无人农场,长长长长长长长长长长长长',
                  style: pfSCStyle(color: ColorsUtil.title, fontSize: font15),
                ),
                SizedBox(
                  height: 5.r,
                ),
                Row(
                  children: [
                    Text(
                      '央广网',
                      style: pfMediumStyle(
                          color: ColorsUtil.content, fontSize: font12),
                    ),
                    SizedBox(
                      width: gap10,
                    ),
                    Text(
                      '1天前',
                      style: pfMediumStyle(
                          color: ColorsUtil.content, fontSize: font12),
                    ),
                  ],
                )
              ],
            ),
          ),
        ],
      ),
    );
  }
}
